<?php

namespace App\Http\Controllers\Api;

use App\Models\FormId;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class FormIdController extends Controller
{
    public function store(Request $request)
    {
        $formId = $request->form_id;
        if (!$formId) {
            return api('require form_id');
        }
        $user = \Auth::user();
        $thirdPartyBind = $user->thirdPartyBinds()->platformWeixinOpen()->firstOrFail();
        $formId = FormId::create([
            'uid' => $user->id,
            'openid' => $thirdPartyBind->openid,
            'form_id' => $formId,
        ]);
        return api(RET_OK, MSG_OK, $formId);
    }
}
